import i18next from 'i18next';
import {useMemo} from 'react';
import {useTranslation} from 'react-i18next';
import {usePathLevel} from './url';

const useTrans = () => {
    const {currentPath: langPath} = usePathLevel(0);
    const trans = useTranslation();

    const t = useMemo(() => {
        i18next.changeLanguage(langPath);
        trans.i18n.changeLanguage(langPath);
        return trans.t;
    }, [langPath]);

    return {t};
};

export default useTrans;
